﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:local="clr-namespace:OMANE.Modules.Builder"
    xmlns:theme="clr-namespace:OMANE.Common.UI.Theme;assembly=OMANE.Common.UI.Theme" 
	mc:Ignorable="d"
	x:Class="ViewEditableParameterSection"
	d:DesignWidth="640" d:DesignHeight="480">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="5"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ListBox ItemsSource="{Binding Groups}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" >
            <ListBox.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Ajouter un groupe" Command="{Binding AddGroupCommand, Mode=OneWay}"/>
                </ContextMenu>
            </ListBox.ContextMenu>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <local:CustomUniformGrid />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <GroupBox Header="{Binding Name}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" d:DesignWidth="281.7" d:DesignHeight="115">
                        <GroupBox.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Inserer un parametre" ItemsSource="{Binding Params}" Command="{Binding AddParameterCommand}">
                                    <MenuItem.ItemTemplate>
                                        <DataTemplate >
                                            <TextBlock Text="{Binding Name}" />
                                        </DataTemplate>
                                    </MenuItem.ItemTemplate>
                                    <MenuItem.ItemContainerStyle>
                                        <Style TargetType="MenuItem">
                                            <Setter Property="Command" Value="{Binding Command, RelativeSource={RelativeSource AncestorType=MenuItem}}" />
                                            <Setter Property="CommandParameter" Value="{Binding}" />
                                        </Style>
                                    </MenuItem.ItemContainerStyle>
                                </MenuItem>

                            </ContextMenu>
                        </GroupBox.ContextMenu>
                        <Grid Margin="0,10,0,0" DataContext="{Binding Mode=OneWay}">
                            <DataGrid SelectionMode="Single" SelectionUnit="Cell" Background="{x:Null}" BorderBrush="{x:Null}" MinHeight="50"  ColumnWidth="*" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" HeadersVisibility="None" GridLinesVisibility="None" AutoGenerateColumns="False"  ItemsSource="{Binding Paramters}" Visibility="Visible" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="False" IsReadOnly="True">
                                <DataGrid.Columns>
                                    <DataGridTemplateColumn CanUserSort="False" CanUserResize="False" CanUserReorder="False">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock VerticalAlignment="Center" Text="{Binding Title, Mode=OneWay}" TextAlignment="Right" Margin="5" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn  CanUserSort="False" CanUserResize="False" CanUserReorder="False" >
                                        <!--<DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate >
                                                <TextBlock Text="{Binding}" Margin="5" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>-->
                                        
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <StackPanel Margin="5" Orientation="Horizontal">
                                                    <ContentControl Width="200" VerticalAlignment="Center" Content="{Binding}" >
                                                        <ContentControl.Resources>
                                                            <DataTemplate x:Key="Default">
                                                                <TextBlock Text="{Binding}" />
                                                            </DataTemplate>
                                                            <DataTemplate x:Key="Boolean">
                                                                <CheckBox Content="Oui-Non" />
                                                            </DataTemplate>
                                                            <DataTemplate x:Key="Date">
                                                                <DatePicker />
                                                            </DataTemplate>
                                                            <DataTemplate x:Key="Time">
                                                              <TextBox  MinWidth="100" />
                                                            </DataTemplate>
                                                            <DataTemplate x:Key="Double">
                                                                <theme:NumericEditor Style="{StaticResource PercentageEditor}"/>
                                                            </DataTemplate>
                                                            <DataTemplate x:Key="Case">
                                                                <ComboBox MinWidth="100" Style="{DynamicResource OMANE_cbx}" />
                                                            </DataTemplate>
                                                            <DataTemplate x:Key="Uncertain">
                                                                <Grid>
                                                                    <Grid.RowDefinitions>
                                                                        <RowDefinition Height="Auto" />
                                                                        <RowDefinition Height="Auto" />
                                                                    </Grid.RowDefinitions>
                                                                    <Grid.ColumnDefinitions>
                                                                        <ColumnDefinition Width="Auto" />
                                                                        <ColumnDefinition Width="Auto" />
                                                                    </Grid.ColumnDefinitions>
                                                                    <TextBlock Text="Moyenne" />
                                                                    <TextBlock Grid.Row="1" Text="Ecart-Type" />
                                                                    <theme:NumericEditor Grid.Column="1" Margin="1" Style="{StaticResource PercentageEditor}"/>
                                                                    <theme:NumericEditor Grid.Column="1" Grid.Row="1" Margin="1" Style="{StaticResource PercentageEditor}"/>
                                                                </Grid>
                                                            </DataTemplate>
                                                        </ContentControl.Resources>
                                                        <ContentControl.ContentTemplateSelector>
                                                            <local:ModelParamTypeTemplateSelector />
                                                        </ContentControl.ContentTemplateSelector>
                                                    </ContentControl>
                                                    
                                                    <!--<TextBox MinWidth="50" Text="{Binding , Mode=OneWay}" />-->
                                                    <Grid>
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="20" />
                                                            <ColumnDefinition Width="Auto" />
                                                        </Grid.ColumnDefinitions>
                                                    
                                                    <RadioButton GroupName="SegmentationGroup" Margin="5,0,0,0" VerticalAlignment="Center" >
                                                        <RadioButton.Visibility>
                                                            <Binding Path="Parameter.IsSegmentable">
                                                                <Binding.Converter>
                                                                    <BooleanToVisibilityConverter />
                                                                </Binding.Converter>
                                                            </Binding>
                                                        </RadioButton.Visibility>
                                                    </RadioButton>
                                                    
                                                    <Button Grid.Column="1" Margin="5,0,0,0" Width="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ActualHeight}"  Content="E" Padding="2" FontWeight="Bold" />
                                                    </Grid>
                                                </StackPanel>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                </DataGrid.Columns>

                                <DataGrid.CellStyle>
                                    <Style TargetType="{x:Type DataGridCell}">
                                        <Setter Property="Background" Value="Transparent"/>
                                        <Setter Property="BorderBrush" Value="Transparent"/>
                                        <Setter Property="BorderThickness" Value="0"/>
                                        <Setter Property="Focusable" Value="False"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type DataGridCell}">
                                                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                                                        <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                                    </Border>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                        <Style.Triggers>
                                            <Trigger Property="IsSelected" Value="True">
                                                <!--<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>-->
                                                <Setter Property="Foreground" Value="Black"/>
                                                <!--<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>-->
                                            </Trigger>
                                            <!--<Trigger Property="IsKeyboardFocusWithin" Value="True">
                                                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}"/>
                                            </Trigger>-->
                                        </Style.Triggers>
                                    </Style>
                                </DataGrid.CellStyle>
                            </DataGrid>
                        </Grid>
                    </GroupBox>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                    <Setter Property="Padding" Value="2,0,0,0"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </Border>                              
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>
        <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" />
        <Expander Grid.Row="2">
            <Expander.Header>
                <StackPanel />
            </Expander.Header>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="5"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <ListView >
                    <ListView.View>
                        <GridView />
                    </ListView.View>
                </ListView>
                <GridSplitter HorizontalAlignment="Stretch" Grid.Column="1" />
                <DataGrid Grid.Column="2" />
            </Grid>
        </Expander>
    </Grid>
</UserControl>